<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class REXML::Document - rexml: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    

    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Element
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-entity_expansion_limit">::entity_expansion_limit</a>
    <li ><a href="#method-c-entity_expansion_limit-3D">::entity_expansion_limit=</a>
    <li ><a href="#method-c-entity_expansion_text_limit">::entity_expansion_text_limit</a>
    <li ><a href="#method-c-entity_expansion_text_limit-3D">::entity_expansion_text_limit=</a>
    <li class="calls-super" ><a href="#method-c-new">::new</a>
    <li ><a href="#method-c-parse_stream">::parse_stream</a>
    <li ><a href="#method-i-3C-3C">#&lt;&lt;</a>
    <li class="calls-super" ><a href="#method-i-add">#add</a>
    <li class="calls-super" ><a href="#method-i-add_element">#add_element</a>
    <li ><a href="#method-i-build">#build</a>
    <li ><a href="#method-i-clone">#clone</a>
    <li ><a href="#method-i-doctype">#doctype</a>
    <li ><a href="#method-i-document">#document</a>
    <li ><a href="#method-i-encoding">#encoding</a>
    <li ><a href="#method-i-expanded_name">#expanded_name</a>
    <li ><a href="#method-i-name">#name</a>
    <li ><a href="#method-i-node_type">#node_type</a>
    <li ><a href="#method-i-record_entity_expansion">#record_entity_expansion</a>
    <li ><a href="#method-i-root">#root</a>
    <li ><a href="#method-i-stand_alone-3F">#stand_alone?</a>
    <li ><a href="#method-i-version">#version</a>
    <li ><a href="#method-i-write">#write</a>
    <li ><a href="#method-i-xml_decl">#xml_decl</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-REXML::Document">
    <h1 id="class-REXML::Document" class="class">
      class REXML::Document
    </h1>

    <section class="description">
    
<p>Represents an XML document.</p>

<p>A document may have:</p>
<ul><li>
<p>A single child that may be accessed via method <a href="Document.html#method-i-root"><code>root</code></a>.</p>
</li><li>
<p>An XML declaration.</p>
</li><li>
<p>A document type.</p>
</li><li>
<p>Processing instructions.</p>
</li></ul>

<h2 id="class-REXML::Document-label-In+a+Hurry-3F">In a Hurry?<span><a href="#class-REXML::Document-label-In+a+Hurry-3F">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>If you’re somewhat familiar with XML and have a particular task in mind, you may want to see the <a href="../doc/rexml/tasks/tocs/master_toc_rdoc.html">tasks pages</a>, and in particular, the <a href="../doc/rexml/tasks/tocs/document_toc_rdoc.html">tasks page for documents</a>.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="DECLARATION">DECLARATION
          <dd><p>A convenient default XML declaration. Use:</p>

<pre class="ruby"><span class="ruby-identifier">mydoc</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">XMLDecl</span>.<span class="ruby-identifier">default</span>
</pre>
        </dl>
        </section>

        <section class="attribute-method-details" class="method-section">
        <header>
        <h3>Attributes</h3>
        </header>

          <div id="attribute-i-entity_expansion_count" class="method-detail">
            <div class="method-heading attribute-method-heading">
              <span class="method-name">entity_expansion_count</span><span
                class="attribute-access-type">[R]</span>
            </div>

            <div class="method-description">
              
              </div>
            </div>
            </section>


                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-entity_expansion_limit" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">entity_expansion_limit</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Get the entity expansion limit. By default the limit is set to 10000.</p>

<p>Deprecated. Use <a href="Security.html#method-c-entity_expansion_limit-3D"><code>REXML::Security.entity_expansion_limit=</code></a> instead.</p>

                              <div class="method-source-code" id="entity_expansion_limit-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 415</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Document</span><span class="ruby-operator">::</span><span class="ruby-identifier ruby-title">entity_expansion_limit</span>
  <span class="ruby-keyword">return</span> <span class="ruby-constant">Security</span>.<span class="ruby-identifier">entity_expansion_limit</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-entity_expansion_limit-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">entity_expansion_limit=</span><span
                                class="method-args">( val )</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Set the entity expansion limit. By default the limit is set to 10000.</p>

<p>Deprecated. Use <a href="Security.html#method-c-entity_expansion_limit-3D"><code>REXML::Security.entity_expansion_limit=</code></a> instead.</p>

                              <div class="method-source-code" id="entity_expansion_limit-3D-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 408</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Document</span><span class="ruby-operator">::</span><span class="ruby-identifier ruby-title">entity_expansion_limit=</span>( <span class="ruby-identifier">val</span> )
  <span class="ruby-constant">Security</span>.<span class="ruby-identifier">entity_expansion_limit</span> = <span class="ruby-identifier">val</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-entity_expansion_text_limit" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">entity_expansion_text_limit</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Get the entity expansion limit. By default the limit is set to 10240.</p>

<p>Deprecated. Use <a href="Security.html#method-c-entity_expansion_text_limit"><code>REXML::Security.entity_expansion_text_limit</code></a> instead.</p>

                              <div class="method-source-code" id="entity_expansion_text_limit-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 429</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Document</span><span class="ruby-operator">::</span><span class="ruby-identifier ruby-title">entity_expansion_text_limit</span>
  <span class="ruby-keyword">return</span> <span class="ruby-constant">Security</span>.<span class="ruby-identifier">entity_expansion_text_limit</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-entity_expansion_text_limit-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">entity_expansion_text_limit=</span><span
                                class="method-args">( val )</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Set the entity expansion limit. By default the limit is set to 10240.</p>

<p>Deprecated. Use <a href="Security.html#method-c-entity_expansion_text_limit-3D"><code>REXML::Security.entity_expansion_text_limit=</code></a> instead.</p>

                              <div class="method-source-code" id="entity_expansion_text_limit-3D-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 422</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Document</span><span class="ruby-operator">::</span><span class="ruby-identifier ruby-title">entity_expansion_text_limit=</span>( <span class="ruby-identifier">val</span> )
  <span class="ruby-constant">Security</span>.<span class="ruby-identifier">entity_expansion_text_limit</span> = <span class="ruby-identifier">val</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-new" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(string = nil, context = {}) &rarr; new_document
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(io_stream = nil, context = {}) &rarr; new_document
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          new(document = nil, context = {}) &rarr; new_document
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns a new REXML::Document object.</p>

<p>When no arguments are given, returns an empty document:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&quot;</span>
</pre>

<p>When argument <code>string</code> is given, it must be a string containing a valid XML document:</p>

<pre class="ruby"><span class="ruby-identifier">xml_string</span> = <span class="ruby-string">&#39;&lt;root&gt;&lt;foo&gt;Foo&lt;/foo&gt;&lt;bar&gt;Bar&lt;/bar&gt;&lt;/root&gt;&#39;</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&lt;root&gt;&lt;foo&gt;Foo&lt;/foo&gt;&lt;bar&gt;Bar&lt;/bar&gt;&lt;/root&gt;&quot;</span>
</pre>

<p>When argument <code>io_stream</code> is given, it must be an IO object that is opened for reading, and when read must return a valid XML document:</p>

<pre class="ruby"><span class="ruby-constant">File</span>.<span class="ruby-identifier">write</span>(<span class="ruby-string">&#39;t.xml&#39;</span>, <span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">d</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-string">&#39;t.xml&#39;</span>, <span class="ruby-string">&#39;r&#39;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">io</span><span class="ruby-operator">|</span>
  <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">io</span>)
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&lt;root&gt;&lt;foo&gt;Foo&lt;/foo&gt;&lt;bar&gt;Bar&lt;/bar&gt;&lt;/root&gt;&quot;</span>
</pre>

<p>When argument <code>document</code> is given, it must be an existing document object, whose context and attributes (but not children) are cloned into the new document:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">children</span>    <span class="ruby-comment"># =&gt; [&lt;root&gt; ... &lt;/&gt;]</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">context</span> = {<span class="ruby-value">raw:</span> <span class="ruby-value">:all</span>, <span class="ruby-value">compress_whitespace:</span> <span class="ruby-value">:all</span>}
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">add_attributes</span>({<span class="ruby-string">&#39;bar&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">0</span>, <span class="ruby-string">&#39;baz&#39;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">1</span>})
<span class="ruby-identifier">d1</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">d</span>)
<span class="ruby-identifier">d1</span>.<span class="ruby-identifier">children</span>   <span class="ruby-comment"># =&gt; []</span>
<span class="ruby-identifier">d1</span>.<span class="ruby-identifier">context</span>    <span class="ruby-comment"># =&gt; {:raw=&gt;:all, :compress_whitespace=&gt;:all}</span>
<span class="ruby-identifier">d1</span>.<span class="ruby-identifier">attributes</span> <span class="ruby-comment"># =&gt; {&quot;bar&quot;=&gt;bar=&#39;0&#39;, &quot;baz&quot;=&gt;baz=&#39;1&#39;}</span>
</pre>

<p>When argument <code>context</code> is given, it must be a hash containing context entries for the document; see <a href="../doc/rexml/context_rdoc.html">Element Context</a>:</p>

<pre class="ruby"><span class="ruby-identifier">context</span> = {<span class="ruby-value">raw:</span> <span class="ruby-value">:all</span>, <span class="ruby-value">compress_whitespace:</span> <span class="ruby-value">:all</span>}
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xml_string</span>, <span class="ruby-identifier">context</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">context</span> <span class="ruby-comment"># =&gt; {:raw=&gt;:all, :compress_whitespace=&gt;:all}</span>
</pre>
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 92</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>( <span class="ruby-identifier">source</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">context</span> = {} )
  <span class="ruby-ivar">@entity_expansion_count</span> = <span class="ruby-value">0</span>
  <span class="ruby-keyword">super</span>()
  <span class="ruby-ivar">@context</span> = <span class="ruby-identifier">context</span>
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">source</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">Document</span>
    <span class="ruby-ivar">@context</span> = <span class="ruby-identifier">source</span>.<span class="ruby-identifier">context</span>
    <span class="ruby-keyword">super</span> <span class="ruby-identifier">source</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">build</span>(  <span class="ruby-identifier">source</span> )
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-parse_stream" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">parse_stream</span><span
                                class="method-args">( source, listener )</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="parse_stream-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 401</span>
<span class="ruby-keyword">def</span> <span class="ruby-constant">Document</span><span class="ruby-operator">::</span><span class="ruby-identifier ruby-title">parse_stream</span>( <span class="ruby-identifier">source</span>, <span class="ruby-identifier">listener</span> )
  <span class="ruby-constant">Parsers</span><span class="ruby-operator">::</span><span class="ruby-constant">StreamParser</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">source</span>, <span class="ruby-identifier">listener</span> ).<span class="ruby-identifier">parse</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-3C-3C" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">&lt;&lt;</span><span
                                class="method-args">( child )</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Document.html#method-i-add">add</a>
                            </div>
                          </div>

                  <div id="method-i-add" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          add(xml_decl) &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          add(doc_type) &rarr; self
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          add(object) &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Adds an object to the document; returns <code>self</code>.</p>

<p>When argument <code>xml_decl</code> is given, it must be an <a href="XMLDecl.html"><code>REXML::XMLDecl</code></a> object, which becomes the XML declaration for the document, replacing the previous XML declaration if any:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">xml_decl</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&quot;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">add</span>(<span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">XMLDecl</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;2.0&#39;</span>))
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">xml_decl</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&lt;?xml version=&#39;2.0&#39;?&gt;&quot;</span>
</pre>

<p>When argument <code>doc_type</code> is given, it must be an <a href="DocType.html"><code>REXML::DocType</code></a> object, which becomes the document type for the document, replacing the previous document type, if any:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">doctype</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&quot;</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">add</span>(<span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">DocType</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>))
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">doctype</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&lt;!DOCTYPE foo&gt;&quot;</span>
</pre>

<p>When argument <code>object</code> (not an <a href="XMLDecl.html"><code>REXML::XMLDecl</code></a> or <a href="DocType.html"><code>REXML::DocType</code></a> object) is given it is added as the last child:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">add</span>(<span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;foo&#39;</span>))
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-comment"># =&gt; &quot;&lt;foo/&gt;&quot;</span>
</pre>
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="add-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 170</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">add</span>( <span class="ruby-identifier">child</span> )
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">XMLDecl</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@children</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">XMLDecl</span>
      <span class="ruby-ivar">@children</span>[<span class="ruby-value">0</span>] = <span class="ruby-identifier">child</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-ivar">@children</span>.<span class="ruby-identifier">unshift</span> <span class="ruby-identifier">child</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">child</span>.<span class="ruby-identifier">parent</span> = <span class="ruby-keyword">self</span>
  <span class="ruby-keyword">elsif</span> <span class="ruby-identifier">child</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">DocType</span>
    <span class="ruby-comment"># Find first Element or DocType node and insert the decl right</span>
    <span class="ruby-comment"># before it.  If there is no such node, just insert the child at the</span>
    <span class="ruby-comment"># end.  If there is a child and it is an DocType, then replace it.</span>
    <span class="ruby-identifier">insert_before_index</span> = <span class="ruby-ivar">@children</span>.<span class="ruby-identifier">find_index</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">x</span><span class="ruby-operator">|</span>
      <span class="ruby-identifier">x</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Element</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">x</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">DocType</span>)
    }
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">insert_before_index</span> <span class="ruby-comment"># Not null = not end of list</span>
      <span class="ruby-keyword">if</span> <span class="ruby-ivar">@children</span>[ <span class="ruby-identifier">insert_before_index</span> ].<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">DocType</span>
        <span class="ruby-ivar">@children</span>[ <span class="ruby-identifier">insert_before_index</span> ] = <span class="ruby-identifier">child</span>
      <span class="ruby-keyword">else</span>
        <span class="ruby-ivar">@children</span>[ <span class="ruby-identifier">insert_before_index</span><span class="ruby-value">-1</span>, <span class="ruby-value">0</span> ] = <span class="ruby-identifier">child</span>
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>  <span class="ruby-comment"># Insert at end of list</span>
      <span class="ruby-ivar">@children</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">child</span>
    <span class="ruby-keyword">end</span>
    <span class="ruby-identifier">child</span>.<span class="ruby-identifier">parent</span> = <span class="ruby-keyword">self</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">rv</span> = <span class="ruby-keyword">super</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;attempted adding second root element to document&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@elements</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
    <span class="ruby-identifier">rv</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Document.html#method-i-3C-3C">&lt;&lt;</a>
                            </div>

                          </div>

                  <div id="method-i-add_element" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          add_element(name_or_element = nil, attributes = nil) &rarr; new_element
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Adds an element to the document by calling <a href="Element.html#method-i-add_element"><code>REXML::Element.add_element</code></a>:</p>

<pre class="ruby"><span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Element</span>.<span class="ruby-identifier">add_element</span>(<span class="ruby-identifier">name_or_element</span>, <span class="ruby-identifier">attributes</span>)
</pre>
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="add_element-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 209</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">add_element</span>(<span class="ruby-identifier">arg</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">arg2</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-identifier">rv</span> = <span class="ruby-keyword">super</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;attempted adding second root element to document&quot;</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@elements</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
  <span class="ruby-identifier">rv</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-clone" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          clone &rarr; new_document
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the new document resulting from executing <code>Document.new(self)</code>.  See <a href="Document.html#method-c-new"><code>Document.new</code></a>.</p>

                              <div class="method-source-code" id="clone-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 120</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">clone</span>
  <span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-doctype" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          doctype &rarr; doc_type or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the <a href="DocType.html"><code>DocType</code></a> object for the document, if it exists, otherwise <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;!DOCTYPE document SYSTEM &quot;subjects.dtd&quot;&gt;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">doctype</span>.<span class="ruby-identifier">class</span> <span class="ruby-comment"># =&gt; REXML::DocType</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">doctype</span>.<span class="ruby-identifier">class</span> <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="doctype-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 241</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">doctype</span>
  <span class="ruby-ivar">@children</span>.<span class="ruby-identifier">find</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">item</span><span class="ruby-operator">|</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">DocType</span> }
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-document" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">document</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="document-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 442</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">document</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-encoding" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          encoding &rarr; encoding_string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the <a href="XMLDecl.html"><code>XMLDecl</code></a> encoding of the document, if it has been set, otherwise the default encoding:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-16&quot;?&gt;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">encoding</span> <span class="ruby-comment"># =&gt; &quot;UTF-16&quot;</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">encoding</span> <span class="ruby-comment"># =&gt; &quot;UTF-8&quot;</span>
</pre>

                              <div class="method-source-code" id="encoding-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 290</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">encoding</span>
  <span class="ruby-identifier">xml_decl</span>().<span class="ruby-identifier">encoding</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-expanded_name" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">expanded_name</span><span
                                class="method-args"> -&gt; empty_string</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an empty string.</p>

                              <div class="method-source-code" id="expanded_name-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 129</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">expanded_name</span>
  <span class="ruby-string">&#39;&#39;</span>
  <span class="ruby-comment">#d = doc_type</span>
  <span class="ruby-comment">#d ? d.name : &quot;UNDEFINED&quot;</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Document.html#method-i-name">name</a>
                            </div>

                          </div>

                  <div id="method-i-name" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">name</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Document.html#method-i-expanded_name">expanded_name</a>
                            </div>
                          </div>

                  <div id="method-i-node_type" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          node_type &rarr; :document
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the symbol <code>:document</code>.</p>

                              <div class="method-source-code" id="node_type-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 110</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">node_type</span>
  <span class="ruby-value">:document</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-record_entity_expansion" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">record_entity_expansion</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="record_entity_expansion-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 435</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">record_entity_expansion</span>
  <span class="ruby-ivar">@entity_expansion_count</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
  <span class="ruby-keyword">if</span> <span class="ruby-ivar">@entity_expansion_count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-constant">Security</span>.<span class="ruby-identifier">entity_expansion_limit</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-string">&quot;number of entity expansions exceeded, processing aborted.&quot;</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-root" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          root &rarr; root_element or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the root element of the document, if it exists, otherwise <code>nil</code>:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;root&gt;&lt;/root&gt;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span> <span class="ruby-comment"># =&gt; &lt;root/&gt;</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">root</span> <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="root-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 225</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">root</span>
  <span class="ruby-identifier">elements</span>[<span class="ruby-value">1</span>]
  <span class="ruby-comment">#self</span>
  <span class="ruby-comment">#@children.find { |item| item.kind_of? Element }</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-stand_alone-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          stand_alone?
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the <a href="XMLDecl.html"><code>XMLDecl</code></a> standalone value of the document as a string, if it has been set, otherwise the default standalone value:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;?xml standalone=&quot;yes&quot;?&gt;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">stand_alone?</span> <span class="ruby-comment"># =&gt; &quot;yes&quot;</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">stand_alone?</span> <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="stand_alone-3F-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 305</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">stand_alone?</span>
  <span class="ruby-identifier">xml_decl</span>().<span class="ruby-identifier">stand_alone?</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-version" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          version &rarr; version_string
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the <a href="XMLDecl.html"><code>XMLDecl</code></a> version of this document as a string, if it has been set, otherwise the default version:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;?xml version=&quot;2.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">version</span> <span class="ruby-comment"># =&gt; &quot;2.0&quot;</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">version</span> <span class="ruby-comment"># =&gt; &quot;1.0&quot;</span>
</pre>

                              <div class="method-source-code" id="version-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 275</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">version</span>
  <span class="ruby-identifier">xml_decl</span>().<span class="ruby-identifier">version</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-write" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          write(output=$stdout, indent=-1, transtive=false, ie_hack=false, encoding=nil)
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          write(options={:output =&gt; $stdout, :indent =&gt; -1, :transtive =&gt; false, :ie_hack =&gt; false, :encoding &rarr; nil})
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Write the XML tree out, optionally with indent.  This writes out the entire XML document, including XML declarations, doctype declarations, and processing instructions (if any are given).</p>

<p>A controversial point is whether <a href="Document.html"><code>Document</code></a> should always write the XML declaration (&lt;?xml version=‘1.0’?&gt;) whether or not one is given by the user (or source document).  <a href="../REXML.html"><code>REXML</code></a> does not write one if one was not specified, because it adds unnecessary bandwidth to applications such as XML-RPC.</p>

<p>Accept Nth argument style and options Hash style as argument. The recommended style is options Hash style for one or more arguments case.</p>

<p><em>Examples</em></p>

<pre class="ruby"><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;&lt;a&gt;&lt;b/&gt;&lt;/a&gt;&quot;</span>).<span class="ruby-identifier">write</span>

<span class="ruby-identifier">output</span> = <span class="ruby-string">&quot;&quot;</span>
<span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;&lt;a&gt;&lt;b/&gt;&lt;/a&gt;&quot;</span>).<span class="ruby-identifier">write</span>(<span class="ruby-identifier">output</span>)

<span class="ruby-identifier">output</span> = <span class="ruby-string">&quot;&quot;</span>
<span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;&lt;a&gt;&lt;b/&gt;&lt;/a&gt;&quot;</span>).<span class="ruby-identifier">write</span>(<span class="ruby-value">:output</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">output</span>, <span class="ruby-value">:indent</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">2</span>)
</pre>

<p>See also the classes in the rexml/formatters package for the proper way to change the default formatting of XML output.</p>

<p><em>Examples</em></p>

<pre class="ruby"><span class="ruby-identifier">output</span> = <span class="ruby-string">&quot;&quot;</span>
<span class="ruby-identifier">tr</span> = <span class="ruby-constant">Transitive</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">tr</span>.<span class="ruby-identifier">write</span>(<span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;&lt;a&gt;&lt;b/&gt;&lt;/a&gt;&quot;</span>), <span class="ruby-identifier">output</span>)
</pre>
<dl class="rdoc-list note-list"><dt>output
<dd>
<p>output an object which supports ‘&lt;&lt; string’; this is where the document will be written.</p>
</dd><dt>indent
<dd>
<p>An integer.  If -1, no indenting will be used; otherwise, the indentation will be twice this number of spaces, and children will be indented an additional amount.  For a value of 3, every item will be indented 3 more levels, or 6 more spaces (2 * 3). Defaults to -1</p>
</dd><dt>transitive
<dd>
<p>If transitive is true and indent is &gt;= 0, then the output will be pretty-printed in such a way that the added whitespace does not affect the absolute <strong>value</strong> of the document – that is, it leaves the value and number of <a href="Text.html"><code>Text</code></a> nodes in the document unchanged.</p>
</dd><dt>ie_hack
<dd>
<p>This hack inserts a space before the /&gt; on empty tags to address a limitation of Internet Explorer.  Defaults to false</p>
</dd><dt>encoding
<dd>
<p><a href="Encoding.html"><code>Encoding</code></a> name as String. Change output encoding to specified encoding instead of encoding in XML declaration. Defaults to nil. It means encoding in XML declaration is used.</p>
</dd></dl>

                              <div class="method-source-code" id="write-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 365</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">write</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">arguments</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span> <span class="ruby-keyword">and</span> <span class="ruby-identifier">arguments</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Hash</span>
    <span class="ruby-identifier">options</span> = <span class="ruby-identifier">arguments</span>[<span class="ruby-value">0</span>]

    <span class="ruby-identifier">output</span>     = <span class="ruby-identifier">options</span>[<span class="ruby-value">:output</span>]
    <span class="ruby-identifier">indent</span>     = <span class="ruby-identifier">options</span>[<span class="ruby-value">:indent</span>]
    <span class="ruby-identifier">transitive</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value">:transitive</span>]
    <span class="ruby-identifier">ie_hack</span>    = <span class="ruby-identifier">options</span>[<span class="ruby-value">:ie_hack</span>]
    <span class="ruby-identifier">encoding</span>   = <span class="ruby-identifier">options</span>[<span class="ruby-value">:encoding</span>]
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">output</span>, <span class="ruby-identifier">indent</span>, <span class="ruby-identifier">transitive</span>, <span class="ruby-identifier">ie_hack</span>, <span class="ruby-identifier">encoding</span>, = <span class="ruby-operator">*</span><span class="ruby-identifier">arguments</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">output</span>   <span class="ruby-operator">||=</span> <span class="ruby-identifier">$stdout</span>
  <span class="ruby-identifier">indent</span>   <span class="ruby-operator">||=</span> <span class="ruby-value">-1</span>
  <span class="ruby-identifier">transitive</span> = <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">transitive</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-identifier">ie_hack</span>    = <span class="ruby-keyword">false</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">ie_hack</span>.<span class="ruby-identifier">nil?</span>
  <span class="ruby-identifier">encoding</span> <span class="ruby-operator">||=</span> <span class="ruby-identifier">xml_decl</span>.<span class="ruby-identifier">encoding</span>

  <span class="ruby-keyword">if</span> <span class="ruby-identifier">encoding</span> <span class="ruby-operator">!=</span> <span class="ruby-string">&#39;UTF-8&#39;</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">output</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">Output</span>)
    <span class="ruby-identifier">output</span> = <span class="ruby-constant">Output</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">output</span>, <span class="ruby-identifier">encoding</span> )
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">formatter</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">indent</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">-1</span>
      <span class="ruby-keyword">if</span> <span class="ruby-identifier">transitive</span>
        <span class="ruby-identifier">require_relative</span> <span class="ruby-string">&quot;formatters/transitive&quot;</span>
        <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Formatters</span><span class="ruby-operator">::</span><span class="ruby-constant">Transitive</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">indent</span>, <span class="ruby-identifier">ie_hack</span> )
      <span class="ruby-keyword">else</span>
        <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Formatters</span><span class="ruby-operator">::</span><span class="ruby-constant">Pretty</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">indent</span>, <span class="ruby-identifier">ie_hack</span> )
      <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Formatters</span><span class="ruby-operator">::</span><span class="ruby-constant">Default</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">ie_hack</span> )
    <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">formatter</span>.<span class="ruby-identifier">write</span>( <span class="ruby-keyword">self</span>, <span class="ruby-identifier">output</span> )
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-xml_decl" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          xml_decl &rarr; xml_decl
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the <a href="XMLDecl.html"><code>XMLDecl</code></a> object for the document, if it exists, otherwise the default <a href="XMLDecl.html"><code>XMLDecl</code></a> object:</p>

<pre class="ruby"><span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">xml_decl</span>.<span class="ruby-identifier">class</span> <span class="ruby-comment"># =&gt; REXML::XMLDecl</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">xml_decl</span>.<span class="ruby-identifier">to_s</span>  <span class="ruby-comment"># =&gt; &quot;&lt;?xml version=&#39;1.0&#39; encoding=&#39;UTF-8&#39;?&gt;&quot;</span>
<span class="ruby-identifier">d</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;&#39;</span>)
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">xml_decl</span>.<span class="ruby-identifier">class</span> <span class="ruby-comment"># =&gt; REXML::XMLDecl</span>
<span class="ruby-identifier">d</span>.<span class="ruby-identifier">xml_decl</span>.<span class="ruby-identifier">to_s</span>  <span class="ruby-comment"># =&gt; &quot;&quot;</span>
</pre>

                              <div class="method-source-code" id="xml_decl-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 258</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">xml_decl</span>
  <span class="ruby-identifier">rv</span> = <span class="ruby-ivar">@children</span>[<span class="ruby-value">0</span>]
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">rv</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">rv</span>.<span class="ruby-identifier">kind_of?</span> <span class="ruby-constant">XMLDecl</span>
  <span class="ruby-ivar">@children</span>.<span class="ruby-identifier">unshift</span>(<span class="ruby-constant">XMLDecl</span>.<span class="ruby-identifier">default</span>)[<span class="ruby-value">0</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-build" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">build</span><span
                                class="method-args">( source )</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="build-source">
            <pre><span class="ruby-comment"># File rexml-3.2.6/lib/rexml/document.rb, line 447</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build</span>( <span class="ruby-identifier">source</span> )
  <span class="ruby-constant">Parsers</span><span class="ruby-operator">::</span><span class="ruby-constant">TreeParser</span>.<span class="ruby-identifier">new</span>( <span class="ruby-identifier">source</span>, <span class="ruby-keyword">self</span> ).<span class="ruby-identifier">parse</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

